package liyuxian.fragment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jxnu.duewang.zmly.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import liyuxian.fragment.bean.LocalRadios;

/**
 * Created by Administrator on 2016/12/8.
 */
public class LocalRadiosAdapter extends RecyclerView.Adapter<LocalRadiosAdapter.ViewHolder> {
    private Context context;
    private List<LocalRadios> list;

    public LocalRadiosAdapter(Context context) {
        this.context = context;
      list = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.bradcast, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.name.setText(list.get(position).getName());
        holder.playCount.setText(list.get(position).getPlayCount());
        holder.programName.setText(list.get(position).getProgramName());
        imageLocal(holder.image,list.get(position).getCoverLarge());

    }
public void imageLocal(ImageView image, String coverSmall){
    Picasso.with(image.getContext())
            .load(coverSmall)
            .into(image);

}
    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addAll(Collection<? extends LocalRadios> top) {
        int size = list.size();
        list.addAll(top);
        notifyItemRangeInserted(size, top.size());

    }


    public static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView image;
        private TextView name;
        private TextView programName;
        private TextView playCount;
        private ImageView vido ;
        private TextView title_text ;
        public ViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.brad_image);
            name = (TextView) itemView.findViewById(R.id.name);
            programName = (TextView) itemView.findViewById(R.id.programName);
            playCount = (TextView) itemView.findViewById(R.id.playCount);
            vido = (ImageView) itemView.findViewById(R.id.vdio);
            title_text = (TextView) itemView.findViewById(R.id.title_text);
            Log.d("4334","324324");
        }
    }
}
